#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m, k, dist[5001];
bool b[5001];
struct Node {
	ll y, v;
	Node(int _y, int _v) {
		y = _y, v = _v;
	};
};
vector<Node> edge[5001];

inline void dijkstra(ll s, ll t) {
	memset(b, false, sizeof(b));
	memset(dist, 127, sizeof(dist));
	dist[s] = 0;
	for (; ; ) {
		ll x = -1;
		for (ll i = 1; i <= n; ++i)
			if (!b[i] && dist[i] < 1 << 30)
				if (x == -1 || dist[i] < dist[x])
					x = i;
		if (x == t || x == -1)
			break;
		b[x] = true;
		for (auto i : edge[x])
			dist[i.y] = min(dist[i.y], dist[x] + i.v);
	}
	if (dist[t] < 1 << 30)
		printf("%lld\n", dist[t]);
	else
		printf("-1\n");
}
int main() {
	scanf("%lld%lld%lld", &n, &m, &k);
	for (ll i = 1; i <= m; ++i) {
		ll x, y, z;
		scanf("%lld%lld%lld", &x, &y, &z);
		edge[x].push_back(Node(y, z));
	}
	for (; k--; ) {
		ll s, t;
		scanf("%lld%lld", &s, &t);
		dijkstra(s, t);
	}
	return 0;
}
